package com.ptswitch.material.pages.contract;

import org.apache.tapestry5.EventConstants;
import org.apache.tapestry5.annotations.OnEvent;
import org.apache.tapestry5.ioc.annotations.Inject;

import com.ptswitch.material.model.base.Upload;
import com.ptswitch.material.pages.base.PageBase;
import com.ptswitch.material.service.ContractAttachmentService;
import com.ptswitch.material.util.WebUtil;
import com.ptswitch.material.util.security.PermissionUtil;

public class DownloadAttachment extends PageBase {
    @Inject
    private ContractAttachmentService uploadSer;

    @OnEvent(value = EventConstants.ACTIVATE)
    Object download(long id) {
        checkPermitted(PermissionUtil.ContractAttachmentDownload);
        Upload upload = uploadSer.findById(id);
        return WebUtil.download(upload);
    }
}
